package org.eclipse.rally.plugin.views;

import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JOptionPane;

import org.eclipse.rally.plugin.utils.FileViewer;
import org.eclipse.rally.plugin.utils.RallyConstants;
import org.eclipse.rally.plugin.utils.SWTResourceManager;
import org.eclipse.rally.plugin.webservice.RallyMain;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

import com.rallydev.webservice.v1_12.domain.Attachment;
import com.rallydev.webservice.v1_12.domain.AttachmentContent;
import com.rallydev.webservice.v1_12.domain.Defect;
import com.rallydev.webservice.v1_12.domain.HierarchicalRequirement;
import com.rallydev.webservice.v1_12.domain.Iteration;
import com.rallydev.webservice.v1_12.domain.Project;
import com.rallydev.webservice.v1_12.domain.Release;
import com.rallydev.webservice.v1_12.domain.Task;

public class UserStoryDetailGUI {

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */

	public static Composite composite;
	public static ScrolledComposite scrolledComposite;
	public static Group group;
	public static Map attachmentMap;
	static String strAttachment = "";
	public static Shell shell;
	public static DefectDetailGUI dbg;
	  static String taskObjRef = "";

	public static void main(String args[]) {
		Display display = new Display();
		shell = new Shell(display);
		shell.setMinimumSize(new Point(400, 1000));
		shell.setLayout(new FillLayout());

		String id = "DE5731";
		TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
		TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText("User Story &Detail");
		// new TaskDetailGUI().taskDetail(tabFolder, tabItem, id,false);

		shell.setSize(900, 894);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		display.dispose();
	}

	public Group userStoryDetail(final TabFolder tabFolder, final TabItem tabItem,
			final String taskRefrence, final String pageName) {
		try {
			HierarchicalRequirement requirement = (HierarchicalRequirement) RallyMain.readTaskWorkProdObject(taskRefrence);
			
			scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
			tabItem.setControl(scrolledComposite);
	        scrolledComposite.setExpandHorizontal(true);
	        scrolledComposite.setExpandVertical(true);
	        
	        composite = new Composite(scrolledComposite, SWT.BORDER);
	        composite.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
	        group = new Group(composite, SWT.BORDER);
	        group.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
	        group.setBounds(10, 10, 860, 797);
	        
	        Label lblId = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblId.setBounds(0, 30, 166, 21);
	        lblId.setText("ID :");
	        lblId.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblId.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblId.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
	        
	        Label  lblName = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblName.setBounds(0, 51, 166, 50);
	        lblName.setText("Name:");
	        lblName.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblName.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblName.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblGeneral = new Label(group, SWT.BORDER);
	        lblGeneral.setBounds(0, 10, 168, 21);
	        lblGeneral.setText("General");
	        lblGeneral.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblGeneral.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
	        lblGeneral.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label lblDescription = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblDescription.setBounds(0, 101, 166, 256);
	        lblDescription.setText("Description:");
	        lblDescription.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblDescription.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblDescription.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label  lblAttachments = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblAttachments.setBounds(1, 357, 166, 65);
	        lblAttachments.setText("Attachments:");
	        lblAttachments.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblAttachments.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblAttachments.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblOwner = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblOwner.setBounds(1, 421, 166, 23);
	        lblOwner.setText("Owner:");
	        lblOwner.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblOwner.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblOwner.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblProject = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblProject.setBounds(1, 444, 166, 24);
	        lblProject.setText("Project:");
	        lblProject.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblProject.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblProject.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblTask = new Label(group, SWT.BORDER);
	        lblTask.setBounds(0, 467, 167, 21);
	        lblTask.setText("User Story");
	        lblTask.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblTask.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
	        lblTask.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label  lblState = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblState.setBounds(1, 487, 166, 21);
	        lblState.setText("Parent :");
	        lblState.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblState.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblState.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
	        
	        Label lblEstimate = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblEstimate.setBounds(0, 529, 166, 21);
	        lblEstimate.setText("State:");
	        lblEstimate.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblEstimate.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblEstimate.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblToDo = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblToDo.setBounds(0, 549, 166, 21);
	        lblToDo.setText("Release:");
	        lblToDo.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblToDo.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblToDo.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblWorkProduct = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblWorkProduct.setBounds(0, 570, 166, 21);
	        lblWorkProduct.setText("Plan Est:");
	        lblWorkProduct.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblWorkProduct.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblWorkProduct.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label  lblFixedOrCheckedIn = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblFixedOrCheckedIn.setBounds(0, 589, 166, 21);
	        lblFixedOrCheckedIn.setText("Actual:");
	        lblFixedOrCheckedIn.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblFixedOrCheckedIn.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblFixedOrCheckedIn.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblCustom = new Label(group, SWT.BORDER);
	        lblCustom.setBounds(0, 508, 167, 21);
	        lblCustom.setText("Schedule");
	        lblCustom.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblCustom.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
	        lblCustom.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label lblNotes = new Label(group, SWT.BORDER);
	        lblNotes.setBounds(0, 610, 166, 24);
	        lblNotes.setText("Notes");
	        lblNotes.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblNotes.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
	        lblNotes.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label lblNotes_1 = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblNotes_1.setBounds(0, 634, 166, 160);
	        lblNotes_1.setText("Notes :");
	        lblNotes_1.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblNotes_1.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblNotes_1.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        
	       final Label editButton = new Label(group, SWT.NONE);
	        editButton.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
	        editButton.setImage(SWTResourceManager.getImage(TaskDetailGUI.class, "/icons/Button-Edit.gif"));
	        editButton.setBounds(727, 10, 40, 19);
	        editButton.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseHover(MouseEvent e) {
					System.out.println("entering into mouseHover....");
					final Cursor cursor = new Cursor(Display.getCurrent(),
							SWT.CURSOR_HAND);

					editButton.setCursor(cursor);

				}
			});
	        editButton.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					System.out.println("entering into addMouseListener..of edit button..");
	                composite.dispose();
	                group.dispose();     	  
	                 new EditUserStoryDetailGUI().edituserstoryDetail(tabFolder, tabItem, taskRefrence ,pageName);	
	                }
			});
	        
	        final Label taskBackButton = new Label(group, SWT.NONE);
        	taskBackButton.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
        	taskBackButton.setImage(SWTResourceManager.getImage(TaskDetailGUI.class, "/icons/Back-enabled.gif"));
        	taskBackButton.setBounds(791, 10, 49, 20);
        	
        	taskBackButton.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseHover(MouseEvent e) {
					System.out.println("entering into mouseHover....");
					final Cursor cursor = new Cursor(Display.getCurrent(),
							SWT.CURSOR_HAND);

					taskBackButton.setCursor(cursor);

				}
			});
        	taskBackButton.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					System.out.println("entering into addMouseListener....");
                    composite.dispose();
                    group.dispose();
          
                    if(pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_USERSTORIES)){
                    	
                    	new UserStoryTabGUI().backToUserStoriesPage(tabFolder);
                    	
                    }else if(pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_DASHBOARD)){
                    	new DashboardGUI().backToDashboardPage(tabItem,tabFolder);
                    	
                    }else if(pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_TASK_DETAILS)){
                    	new TaskDetailGUI().backToTaskDetailPage(tabFolder, tabItem, taskObjRef, pageName);
                    }
                    
                }
			});
	        	Label label4 = new Label(group, SWT.NONE);
	        	label4.setBounds(167, 10, 683, 20);
	        	label4.setBackground(SWTResourceManager.getColor(122, 150, 223));
	       
	       
	        	Label lblIdVal = new Label(group, SWT.RIGHT);
	        	lblIdVal.setBounds(172, 31, 166, 20);
	        	 if(requirement.getFormattedID() != null){
	             	lblIdVal.setText(requirement.getFormattedID());
	             } else {
	         			lblIdVal.setText("");
	             }
	        	lblIdVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        	lblIdVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        	lblIdVal.setBackground(SWTResourceManager.getColor(255, 255, 255));
	        	lblIdVal.setAlignment(SWT.LEFT);
	       
	       
	        	StyledText lblNameVal = new StyledText(group, SWT.BORDER | SWT.SINGLE);
	        	//Browser lblNameVal = new Browser(group, SWT.BORDER);
	        	lblNameVal.setBounds(172, 51, 668, 49);
	        	 if(requirement.getName() != null)
	             	lblNameVal.setText(requirement.getName());
	     		else
	     			lblNameVal.setText("");
	        	lblNameVal.setEditable(true);
	        	
	        	
	        	Browser lblDescVal = new Browser(group, SWT.BORDER);
	        	lblDescVal.setBounds(172, 101, 674, 253);
	        	  if(requirement.getDescription() != null)
	              	lblDescVal.setText(requirement.getDescription());
	              else
	              	lblDescVal.setText("");
	        	  lblDescVal.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
	              lblDescVal.setEnabled(false);
	              lblDescVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	              lblDescVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	              lblDescVal.setBackground(SWTResourceManager.getColor(255, 255, 255));
	              
	              
	              getAttachment(requirement);
	              ScrolledComposite scrolledComposite_1 = new ScrolledComposite(group, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
	              scrolledComposite_1.setBounds(172, 357, 679, 60);
	              scrolledComposite_1.setExpandHorizontal(true);
	              scrolledComposite_1.setExpandVertical(true);
	              Link attachmentLink  = new Link(group, SWT.BORDER |SWT.V_SCROLL|SWT.H_SCROLL);
	               attachmentLink.setText(strAttachment);
	             //  attachmentLink.setBounds(172, 357, 679, 60);
	               attachmentLink.addListener(SWT.Selection, new Listener() {
	                  public void handleEvent(Event event) {
	                 	 try{
	                 	 String strFileName = event.text;
	                 	 AttachmentContent content =  (AttachmentContent)attachmentMap.get(strFileName);
	                 	 byte[] fileBArray =  (byte[])content.getContent(); 
	                 	 FileOutputStream fos = new FileOutputStream(strFileName);
	                 	 fos.write(fileBArray);
	                 	 fos.close();
	                 	 File file = new File(strFileName);
	                 	 FileViewer.viewFile(file);
	                 	 }catch(Exception r){
	                 		 r.printStackTrace();
	                 	 }
	                  }
	                });
	               attachmentLink.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
	               attachmentLink.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	               attachmentLink.setBackground(SWTResourceManager.getColor(
	                       SWT.COLOR_LIST_BACKGROUND));
	               scrolledComposite_1.setContent(attachmentLink);
	               scrolledComposite_1.setMinSize(attachmentLink.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	               Label lblOwnerVal = new Label(group, SWT.NONE);
	        	lblOwnerVal.setBounds(172, 420, 289, 21);
	        	if(requirement.getOwner() != null)
	          	  lblOwnerVal.setText(requirement.getOwner());
	          	else
	          	  lblOwnerVal.setText("");
	        	lblOwnerVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	            lblOwnerVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	            lblOwnerVal.setBackground(SWTResourceManager.getColor(255, 255, 255));
	            lblOwnerVal.setAlignment(SWT.LEFT);
	      
	        	 Label lblProjectVal = new Label(group, SWT.NONE);
	             lblProjectVal.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getProject() != null){
	            	 Project project = requirement.getProject();  
	            	 project =  (Project)RallyMain.readProject(project.getRef());
	             	lblProjectVal.setText(project.getName());
	             }else
	             	lblProjectVal.setText("");
	             lblProjectVal.setBounds(172, 444, 289, 24);
	             lblProjectVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             lblProjectVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             lblProjectVal.setBackground(SWTResourceManager.getColor(255, 255, 255));
	             lblProjectVal.setAlignment(SWT.LEFT);
	       
	             Label parent = new Label(group, SWT.NONE);
	             parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getParent() != null){
	            	 HierarchicalRequirement req = requirement.getParent();
	            	 req = (HierarchicalRequirement)RallyMain.readUserStory(req.getRef());
	            	 if(req.getFormattedID() != null)
	            	   parent.setText(req.getFormattedID());
	            	 else
		            	 parent.setText("");
	             }else
	            	 parent.setText("");
	             parent.setBounds(172, 487, 112, 21);
	             parent.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             parent.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             parent.setBackground(SWTResourceManager.getColor(255, 255, 255));
	             parent.setAlignment(SWT.LEFT);
	             
	             Label lblEstimateVal = new Label(group, SWT.NONE);
	             lblEstimateVal.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getScheduleState() != null){
	            	 lblEstimateVal.setText(requirement.getScheduleState());
	             }else
	            	 lblEstimateVal.setText("");
	             lblEstimateVal.setBounds(171, 529, 128, 20);
	             lblEstimateVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             lblEstimateVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             lblEstimateVal.setBackground(SWTResourceManager.getColor(255, 255, 255));
	             lblEstimateVal.setAlignment(SWT.LEFT);
	        
	             Label lblRelease = new Label(group, SWT.NONE);
	             lblRelease.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getRelease() != null){
	            	 Release release =  requirement.getRelease();
	            	 release = (Release)RallyMain.readRelease(release.getRef());
	                lblRelease.setText(release.getName());
	             }else
	            	 lblRelease.setText("");
	             lblRelease.setBounds(171, 549, 113, 21);
	             lblRelease.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             lblRelease.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             lblRelease.setBackground(SWTResourceManager.getColor(255, 255, 255));
	             lblRelease.setAlignment(SWT.LEFT);
		        	
	            Link PlanEst = new Link(group,SWT.NONE);
	             PlanEst.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getPlanEstimate() != null){
	            	 PlanEst.setText(String.valueOf(requirement.getPlanEstimate()));
	             }else
	            	 PlanEst.setText("");
	             PlanEst.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             PlanEst.setBounds(171, 570, 145, 21);
	        
	             Label textActual = new Label(group, SWT.NONE);
	             textActual.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             if(requirement.getTaskActualTotal() != null)
	            	 textActual.setText(String.valueOf(requirement.getTaskActualTotal()));
	 	        else
	 	        	textActual.setText("");
	             textActual.setBounds(172, 589, 145, 21);
	             textActual.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             textActual.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             textActual.setBackground(SWTResourceManager.getColor(255, 255, 255));
	             textActual.setAlignment(SWT.LEFT);
	       
	             Browser lblNotesVal = new Browser(group, SWT.BORDER);
	    		 if(requirement.getNotes()!= null)
	    			 lblNotesVal.setText(requirement.getNotes());
	    	    		else
	    	    			lblNotesVal.setText("");
	    		 lblNotesVal.setBounds(172, 635, 679, 160);
	       
	        	Label lblBlocked = new Label(group, SWT.BORDER | SWT.RIGHT);
	        	lblBlocked.setBounds(566, 529, 119, 21);
	        	lblBlocked.setText("Blocked:");
	        	lblBlocked.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        	lblBlocked.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        	lblBlocked.setBackground(SWTResourceManager.getColor(216, 228, 248));
	       
	        
	        	Label lblBlockedVal = new Label(group, SWT.NONE);
	        	lblBlockedVal.setBounds(691, 529, 105, 21);
	        	if(requirement.getBlocked() != null)
	            	lblBlockedVal.setText(String.valueOf(requirement.getBlocked()));
	            else
	            	lblBlockedVal.setText("");
	        	 lblBlockedVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
	             lblBlockedVal.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	             lblBlockedVal.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	             lblBlockedVal.setAlignment(SWT.LEFT);
	       
	       
	        	Label lblActuals = new Label(group, SWT.BORDER | SWT.RIGHT);
	        	lblActuals.setBounds(566, 549, 119, 21);
	        	lblActuals.setText("Iteration:");
	        	lblActuals.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        	lblActuals.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        	lblActuals.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        	Label txtIteration = new Label(group, SWT.NONE);
	            txtIteration.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	        	if(requirement.getIteration()!= null){
	        		Iteration itration = requirement.getIteration();
	        		itration = (Iteration)RallyMain.readIteration(itration.getRef());
	            	txtIteration.setText(itration.getName());
	        	}else
	            	txtIteration.setText("");
	        	txtIteration.setBounds(691, 551, 105, 19);
	            txtIteration.setForeground(SWTResourceManager.getColor(0, 0, 0));
	            txtIteration.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	            txtIteration.setBackground(SWTResourceManager.getColor(255, 255, 255));
	            txtIteration.setAlignment(SWT.LEFT);
	            
	        Label label_21 = new Label(group, SWT.BORDER);
	        label_21.setBounds(167, 484, 694, 3);
	        label_21.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        label_21.setFont(SWTResourceManager.getFont("Times New Roman", 13, SWT.BOLD));
	        label_21.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label label_22 = new Label(group, SWT.BORDER);
	        label_22.setBounds(167, 525, 694, 3);
	        label_22.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        label_22.setFont(SWTResourceManager.getFont("Times New Roman", 13, SWT.BOLD));
	        label_22.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label label_23 = new Label(group, SWT.BORDER);
	        label_23.setBounds(167, 631, 694, 3);
	        label_23.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        label_23.setFont(SWTResourceManager.getFont("Times New Roman", 13, SWT.BOLD));
	        label_23.setBackground(SWTResourceManager.getColor(122, 150, 223));
	        
	        Label label = new Label(group, SWT.SEPARATOR);
	        label.setBounds(167, 30, 1, 764);
	        label.setForeground(SWTResourceManager.getColor(49, 106, 197));
	        label.setBackground(SWTResourceManager.getColor(49, 106, 197));
	        
	        Label txtTaskEst = new Label(group, SWT.BORDER | SWT.RIGHT);
	        txtTaskEst.setBounds(566, 570, 119, 21);
	        txtTaskEst.setText("Task Est:");
	        txtTaskEst.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        txtTaskEst.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        txtTaskEst.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lblTaskEst = new Label(group, SWT.NONE);
	        lblTaskEst.setBounds(691, 570, 105, 21);
	        if(requirement.getTaskEstimateTotal() != null)
	        	lblTaskEst.setText(String.valueOf(requirement.getTaskEstimateTotal()));
	        else
	        	lblTaskEst.setText("");
	        lblTaskEst.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblTaskEst.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblTaskEst.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	        lblTaskEst.setAlignment(SWT.LEFT);
	        
	        Label lblToDo_1 = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblToDo_1.setBounds(566, 590, 119, 21);
	        lblToDo_1.setText("To Do:");
	        lblToDo_1.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblToDo_1.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblToDo_1.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label lbltodo = new Label(group, SWT.NONE);
	        lbltodo.setBounds(691, 592, 105, 19);
	        lbltodo.setText("---");
	        lbltodo.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lbltodo.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lbltodo.setBackground(SWTResourceManager.getColor(255, 255, 255));
	        lbltodo.setAlignment(SWT.LEFT);
	        
	        Label lblPackage = new Label(group, SWT.BORDER | SWT.RIGHT);
	        lblPackage.setBounds(566, 423, 119, 21);
	        lblPackage.setText("Package:");
	        lblPackage.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        lblPackage.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        lblPackage.setBackground(SWTResourceManager.getColor(216, 228, 248));
	        
	        Label txtPackage = new Label(group, SWT.NONE);
	        txtPackage.setBounds(691, 423, 105, 21);
	        if(requirement.get_package() != null)
	        	txtPackage.setText(requirement.get_package());
	        else
	        	txtPackage.setText("");
	        txtPackage.setForeground(SWTResourceManager.getColor(0, 0, 0));
	        txtPackage.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
	        txtPackage.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
	        txtPackage.setAlignment(SWT.LEFT);
	        
	       
	        scrolledComposite.setContent(composite);
	        scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		 
		 } catch (Exception e) {
			e.printStackTrace();
		}

		return group;
	}

	public static void getAttachment(HierarchicalRequirement req) {

		attachmentMap = new HashMap();
		strAttachment = "";
		if (req.getAttachments() != null) {
			Attachment[] attachment = req.getAttachments();
			for (Object obj : attachment) {
				Attachment attach = (Attachment) obj;
				attach = (Attachment) RallyMain.readAttachemntObject(attach
						.getRef());
				AttachmentContent content = (AttachmentContent) RallyMain
						.readAttachemntContentObject(attach.getContent()
								.getRef());
				System.out.println(attach.getName() + "----"
						+ content.getContent() + "--"
						+ attach.getContent().getType());
				attachmentMap.put(attach.getName(), content);
				strAttachment += "<A>" + attach.getName() + "</A> \n";
			}

		}
	}

	public static String getWorkProductName(String objRef) {
		String workProdName = "";
		String[] strTokens = null;
		if (objRef != null) {
			strTokens = objRef.split("/");

			for (int i = 0; i < strTokens.length; i++) {
				if (strTokens[i].equalsIgnoreCase("hierarchicalrequirement")) {
					HierarchicalRequirement hr = (HierarchicalRequirement) RallyMain
							.readTaskWorkProdObject(objRef);
					workProdName += "<A>" + hr.getFormattedID() + ":" + " "
							+ hr.getName() + "</A> \n";

					break;
				} else if (strTokens[i].equalsIgnoreCase("defect")) {
					Defect defect = (Defect) RallyMain.readDefectObject(objRef);
					workProdName += "<A>" + defect.getFormattedID() + ":" + " "
							+ defect.getName() + "</A> \n";

					break;
				} else if (strTokens[i].equalsIgnoreCase("task")) {
					Task task = (Task) RallyMain.readTaskObject(objRef);
					workProdName += "<A>" + task.getFormattedID() + ":" + " "
							+ task.getName() + "</A> \n";
					break;
				}

			}
		}

		return workProdName;
	}

	public void backToUserDetailPage(TabFolder tabFolder, TabItem tabItem,
			String taskRefrence,String pageName) {
		userStoryDetail(tabFolder, tabItem, taskRefrence, pageName);
		
	}
	 public static void goToUserStorieDetails(TabFolder tabFolder, TabItem tabItem,
				String userStoryRef, String pageName,String taskRef){
	    	
	    	taskObjRef = taskRef;
	    	new UserStoryDetailGUI().userStoryDetail(tabFolder, tabItem, userStoryRef, pageName);
	    	
	    }
	
}